﻿@model EvertonApp.AdminWeb.Models.ComercioModel

@{
    ViewBag.Title = "ComercioView";
}


<script type="text/javascript">
    $(document).ready(function () {
        $("#CreateComercio").live("click", function (e) {
            // e.preventDefault(); use this or return false
            var url = $(this).attr('href');
            $("#dialog-edit").dialog({
                title: 'Crear Comercio',
                autoOpen: false,
                resizable: false,
                show: { effect: 'drop', direction: "up" },
                modal: true,
                draggable: true,
                open: function (event, ui) {
                    $(this).load(url);
                }, close: function (event, ui) {
                    $(this).dialog('close');
                }
            });
            $("#dialog-edit").dialog('open'); return false;
        });
        
        $(".editDialog").live("click", function (e) {
            // e.preventDefault(); use this or return false
            var url = $(this).attr('href');
            $("#dialog-edit").dialog({
                title: 'Editar Comercio',
                autoOpen: false,
                resizable: false,
                show: { effect: 'drop', direction: "up" },
                modal: true,
                draggable: true,
                open: function (event, ui) {
                    $(this).load(url);
                }, close: function (event, ui) {
                    $(this).dialog('close');
                }
            });
            $("#dialog-edit").dialog('open');
            return false;
        });
        
        $(".confirmDialog").live("click", function (e) {
            // e.preventDefault(); use this or return false
            var url = $(this).attr('href');
            $("#dialog-confirm").dialog({
                autoOpen: false,
                resizable: false,
                height: 170,
                width: 350,
                show: { effect: 'drop', direction: "up" },
                modal: true,
                draggable: true,
                buttons: {
                    "OK": function () {
                        $(this).dialog("close");
                        window.location = url;
                    }, "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
            });
            $("#dialog-confirm").dialog('open');
            return false;
        });
        
        $(".viewDialog").live("click", function (e) {
            // e.preventDefault(); use this or return false
            var url = $(this).attr('href');
            $("#dialog-view").dialog({
                title: 'Ver Comercio',
                autoOpen: false,
                resizable: false,
                height: 250,
                width: 400,
                show: { effect: 'drop', direction: "up" },
                modal: true,
                draggable: true,
                open: function (event, ui) {
                    $(this).load(url);
                },
                buttons: {
                    "Close": function () {
                        $(this).dialog("close");
                    }
                },
                close: function (event, ui) {
                    $(this).dialog('close');
                }
            });
            $("#dialog-view").dialog('open');
            return false;
        });
        
        $("#btncancel").live("click", function (e) {
            // location.reload(true);
            $("#dialog-edit").dialog('close');
        });
    });
</script>

<div style="color: Green; font-weight: bold">
    @TempData["msg"]
</div>

<button type="button" class="btn btn-primary btn-large" onclick="funcion();">Crear Comercio</button>

<center>
<div id="divGridComercios">
    @if (@Model.Comercios != null && @Model.Comercios.Count() > 0)
    {
        WebGrid grid = new WebGrid(defaultSort: "Nombre", rowsPerPage: 8);
        grid.Bind(Model.Comercios, autoSortAndPage: true, rowCount: Model.Comercios.Count());
        @grid.GetHtml(
            fillEmptyRows: false,
            alternatingRowStyle: "alternate-row",
            tableStyle: "table table-striped table-bordered table-condensed",
            mode: WebGridPagerModes.All,
            //firstText: "<< Primera",
            //previousText: "< Anterior",
            //nextText: "Siguiente >",
            //lastText: "Última >>",
            columns: new[]{
                //grid.Column("IdComercio",header: "Nº Comercio", canSort: false),
                grid.Column("Nombre",header: "Nombre", canSort: false),
                grid.Column("Direccion",header: "Dirección", canSort: false),
                grid.Column("Telefono",header: "Teléfono", canSort: false), 
                grid.Column("",header: "Acciones", format:@<text>
                    @Ajax.ActionLink("Eliminar", "EliminarComercio", "Comercio", new { IdComercio = item.IdComercio }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divGridComercios" })
                    @Ajax.ActionLink("Editar", "EditComercio", "Comercio", new { IdComercio = item.IdComercio, Nombre = item.Nombre, Direccion = item.Direccion, Telefono = item.Telefono }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divGridComercios" })

                    </text> )}
        )
    }
    else
    {
        {@Html.Label("No se han encontrado comercios.")}
    }
</div>
</center> 
